﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<!--/* 加载IE8兼容性片段 */-->
<head>
    <title>规则管理</title>
    <!--/* 加载全局样式 */-->
    <th:block th:replace="common/thinDecorator::globalStyle"></th:block>
    <!--/* 加载全局主题样式 */-->
    <th:block th:replace="common/thinDecorator::globalThemeStyle"></th:block>
    <!--/* 加载全局布局样式 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutStyle"></th:block>
</head>

<body class="page-content-white page-container-bg-solid" style="overflow-x: hidden;">
<div class="page-wrapper">
    <!-- BEGIN CONTAINER -->
    <div class="page-container">
        <!-- BEGIN CONTENT -->
        <div class="page-content-wrapper">
            <!-- BEGIN CONTENT BODY -->
            <div class="page-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="portlet light" style="margin-bottom: 0px;">
                            <div class="portlet-title">
                                <div class="caption font-blue">
                                    <i class="fa fa-table font-blue"></i>数据源管理
                                </div>
                                <div class="actions">
                                    <a href="/qa/ruleManager/detail" class="list-btn ">新增
                                    </a>
                                </div>
                                <div class="actions">
                                    <a href="javascript:dataList.updateInfo()" class="list-btn ">修改
                                    </a>
                                </div>

                                <div class="actions">
                                    <a href="javascript:dataList.deleteByInfo()" class="list-btn ">删除
                                    </a>
                                </div>
                                <div class="actions">
                                    <a href="javascript:App.search();" class="list-btn ">查询
                                    </a>
                                </div>
                                <div class="actions">
                                    <a href="javascript:App.reset();" class="list-btn ">重置
                                    </a>
                                </div>
                            </div>
                            <div class="portlet-body">
                                <table id="table" style="width:100%;"></table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- END CONTENT BODY -->
        </div>
        <!-- END CONTENT -->
    </div>
</div>
<div id="scripts">
    <!--/* 加载IE8兼容性脚本 */-->
    <th:block th:replace="common/thinDecorator::IE8FixScripts"/>
    <!--/* 加载核心插件脚本 */-->
    <th:block th:replace="common/thinDecorator::corePluginsScripts"/>
    <!--/* 加载全局主题脚本 */-->
    <th:block th:replace="common/thinDecorator::globalThemeScripts"/>
    <!--/* 加载全局布局脚本 */-->
    <th:block th:replace="common/thinDecorator::globalLayoutScripts"/>
    <th:block th:replace="common/thinDecorator::globalsetupScripts"/>
    <script th:inline="javascript">
        $(function () {
            dataList.init();
        });
        var dataList = {
            easyuiTableInput: {},//记录查询框输入值
            //初始化
            init: function () {
                this.easyuiTableInput = localStorageManage.get("table", "searchForm");
                if (!this.easyuiTableInput) {
                    this.easyuiTableInput = {
                        searchData: {},
                        queryParams: {},
                    };
                } else {
                    //写form表单查询
                }
                var height = App.countHeight("table");
                console.log("height is " + height)
                this.createDataGrid();
            },
            updateInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length != 1) {
                    layer.msg("请有且选择一行数据编辑", {icon: 2, time: 2000, shift: 6});
                    return false;
                }
                window.location.href = "/qa/datasource/detail?id=" + row[0].id;
            },
            deleteByInfo: function () {
                var row = $("#table").datagrid("getSelections");
                if (row.length < 1) {
                    layer.msg("请至少选择一行数据", {icon: 2, time: 2000, shift: 6});
                    return false;
                }
                layer.confirm('确定删除吗？', {
                        title: '删除操作',
                        icon: 3,
                        area: ['340px', '160px'], //弹框的大小
                        btn: ['确定', '取消'] //按钮
                    }, function (index) {
                        //点击“确定”执行的操作
                        var ids = [];
                        for (var i = 0; i < row.length; i++) {
                            ids.push(row[i].id);
                        }
                        $.ajax({
                            url: "/qa/datasource/remove",
                            type: "post",
                            data: {
                                ids: ids.join(",")
                            }
                        }, function (result) {
                            layer.msg(result.msg);
                        }, "json");
                        layer.close(index);
                        $("#table").datagrid("reload");
                    }, function () {
                        //点击“取消”执行的操作
                        layer.close();
                    }
                )
            },
            createDataGrid: function () {
                $("#table").datagrid({
                    url: "/qa/ruleManager/datagrid",
                    height: App.getPortletInnerHeight(),
                    queryParams: this.easyuiTableInput.queryParams,
                    frozenColumns: [
                        [
                            {field: 'checkbox', checkbox: true, align: "center", width: 35,},
                            {
                                field: 'number',
                                title: '序号',
                                align: "center",
                                width: 35,
                                formatter: function (data, row, index) {
                                    return index + 1;
                                }
                            },
                        ]
                    ],
                    columns: [
                        [

                            {
                                "field": "createTime", title: "创建时间", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "cnName", title: "规则名称", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "ruleTemplateName", title: "规则模板", width: 180, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "datasourceName", title: "数据源", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "dbName", title: "数据库名", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "tableName", title: "数据表名", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "tableFields", title: "数据字段", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            },
                            {
                                "field": "sqlWhere", title: "过滤条件", width: 140, sortable: false,
                                formatter: function (data, row, index) {
                                    return data;
                                }
                            }
                        ]
                    ],
                    fitColumns: false,//自适应
                    remoteFilter: true,
                    remoteSort: true,
                    clientPaging: false,
                    singleSelect: false,//单选
                    checkOnSelect: true,
                    striped: true, //表格设置为条纹
                    emptyMsg: "表中数据为空",
                    pagination: true,//分页
                    pagePosition: "bottom",
                    pageList: [20, 50, 100],
                    pageSize: 20,
                    automaticPolling: false,
                    onDblClickRow: function (rowIndex, row) {
                        window.location.href = "/qa/datasource/detail?id=" + row.id;
                    }
                });
                this.createFilter();
            },
            //模糊查询
            createFilter: function () {
                $('#table').datagrid('enableFilter', [
                    {"field": "number", type: 'label',},
                    {
                        "field": "createTime", type: 'label', options: {
                            value: dataList.easyuiTableInput.searchData.createTime,
                        }
                    },
                    {
                        "field": "cnName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.cnName,
                        }
                    },
                    {
                        "field": "ruleTemplateName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.ruleTemplateName,
                        }
                    },
                    {
                        "field": "datasourceName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.datasourceName,
                        }
                    },
                    {
                        "field": "dbName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.dbName,
                        }
                    },
                    {
                        "field": "tableName", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.tableName,
                        }
                    },
                    {
                        "field": "tableFields", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.tableFields,
                        }
                    },
                    {
                        "field": "sqlWhere", type: 'textbox', options: {
                            value: dataList.easyuiTableInput.searchData.sqlWhere,
                        }
                    },
                ]);
                var searchBtn = '<a class="table-action" style="margin-left: 1px" onclick="App.search()">查询</a>';
                $('.datagrid-filter-row td[field="number"]').html(searchBtn);
            },
            edit: function () {
                var row = $("#table").datagrid("getSelected");
                if (0 !== row.stateId) {
                    layer.msg("该数据无法编辑", {icon: 2, time: 2000, shift: 6});
                    return false;
                }
                layer.msg("该数据无法编辑", {icon: 2, time: 2000, shift: 6});
            },
            back: function () {
                layer.msg("该数据无法编辑", {icon: 2, time: 2000, shift: 6});
            },
        };
    </script>
</div>
<!-- END CONTAINER -->
</body>

</html>